 //Tuesday, March 16 2010, 08:53:28
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class ColorfulStrings
{
public:
	string getKth(int n, int k)
	{
		int upLimit, downLimit;
		string down(n - 1, '0');
		down = "1" + down;
		string up(n, '9');
		stringstream s1(down);
		s1 >> downLimit;
		stringstream s2(up);
		s2 >> upLimit;
		int count = 0;
		for (int i = downLimit; i <= upLimit; i++)
		{
			stringstream ss;
			ss << i;
			//			cout << ss.str() << endl;
			if (iscolorful(ss.str()))
			{
				count++;
				cout << ss.str() << endl;
				if (count == k)
					return ss.str();
			}
		}
		return "";
	}
	bool iscolorful(string s)
	{
		int res = (int)pow(2.0, (int)s.size()) - 1;
		set<int> w;
		set<int> v;
		set<int>::iterator it;
		long long product = 1;
		for (int i = 0; i < s.size(); i++)
		{
			product *= (s[i] - '0');
			w.insert(s[i] - '0');
		}
		if (s.size() == 1)
			return true;
		if (w.size() != s.size())
			return false;
		bool flag = true;
		v = w;
		while(flag == true)
		{
			flag = false;
			for(it=v.begin(); it!=v.end(); it++)
			{
				w.insert(product / ((*it) - '0'));
				if(w.size() > v.size())
				{
					flag = true;
					break;
				}
			}
			v = w;
		}
		w.insert(product);
		return w.size()==res ? true : false;
	}
};
